import { NodeSize } from '../config'

export default function uniqueRowsByHashSet(flow) {
  flow.register('UniqueRowsByHashSet', ({ PolygonNode, PolygonNodeModel, h }) => {
    class Node extends PolygonNode {
      getIconShape() {
        return h(
          'svg',
          {
            width: NodeSize,
            height: NodeSize,
            viewBox: '0 0 1024 1024'
          },
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M907.971048 492.665905v-3.072l-3.169524-0.048762-55.515429-54.905905-17.139809 17.334857 37.351619 36.937143c-187.684571-7.070476-235.032381-71.655619-235.032381-294.034286V76.8H93.159619v180.175238h501.321143c7.192381 139.166476 43.76381 223.817143 163.986286 257.389714-97.182476 38.521905-150.966857 122.197333-162.889143 252.65981H93.159619v180.175238h541.305905v-121.465905c0-190.464 73.728-282.258286 237.763047-293.473524l-40.082285 39.619048 17.139809 17.334857 78.165334-77.287619-19.480381-19.260952zM599.552 204.8h-6.534095v10.727619H134.607238V204.8h-5.534476V169.20381h5.534476V118.247619h458.410667v50.956191h6.534095V204.8z m0 690.224762h-6.534095v10.727619H134.607238v-10.727619h-5.534476v-35.596191h5.534476v-50.980571h458.410667v50.980571h6.534095v35.596191z'
            }
          ),
          h(
            'path',
            {
              fill: '#EFF9FE',
              d: 'M551.18019 169.20381h41.813334V118.247619H134.607238v50.956191h42.788572V204.8H134.607238v10.727619h458.410667V204.8h-41.813334V169.20381zM229.888 166.4H181.49181v-35.59619h48.371809v35.59619zM282.940952 204.8H234.593524V169.20381h48.347428V204.8z m52.687238-38.4h-48.347428v-35.59619h48.347428v35.59619zM388.510476 204.8H340.114286V169.20381h48.371809V204.8z m52.857905-38.4h-48.37181v-35.59619h48.37181v35.59619z m52.662857 38.4h-48.371809V169.20381h48.371809V204.8z m53.052952-38.4h-48.347428v-35.59619h48.347428v35.59619z'
            }
          ),
          h(
            'path',
            {
              fill: '#EC0800',
              d: 'M287.256381 130.80381h48.347429v35.59619h-48.347429zM181.49181 130.80381h48.371809v35.59619H181.49181zM392.97219 130.80381h48.37181v35.59619h-48.37181zM234.593524 169.20381h48.347428V204.8H234.593524zM177.39581 169.20381H129.072762V204.8h48.323048zM340.114286 169.20381h48.371809V204.8H340.114286zM498.736762 130.80381h48.347428v35.59619h-48.347428zM445.635048 169.20381h48.371809V204.8h-48.371809zM551.18019 169.20381V204.8h48.37181V169.20381h-6.534095zM234.715429 328.874667v381.659428h29.281523v-176.201143h199.582477v176.201143h29.257142V328.874667h-29.257142v176.225523h-199.582477v-176.225523z'
            }
          ),
          h(
            'path',
            {
              fill: '#EFF9FE',
              d: 'M551.18019 859.428571h41.813334v-50.980571H134.607238v50.980571h42.788572v35.596191H134.607238v10.727619h458.410667v-10.727619h-41.813334v-35.596191z m-321.29219-2.803809H181.49181v-35.596191h48.371809v35.596191z m53.052952 38.4H234.593524v-35.596191h48.347428v35.596191z m52.687238-38.4h-48.347428v-35.596191h48.347428v35.596191z m52.882286 38.4H340.114286v-35.596191h48.371809v35.596191z m52.857905-38.4h-48.37181v-35.596191h48.37181v35.596191z m52.662857 38.4h-48.371809v-35.596191h48.371809v35.596191z m53.052952-38.4h-48.347428v-35.596191h48.347428v35.596191z'
            }
          ),
          h(
            'path',
            {
              fill: '#EC0800',
              d: 'M287.256381 821.028571h48.347429v35.596191h-48.347429zM181.49181 821.028571h48.371809v35.596191H181.49181zM392.97219 821.028571h48.37181v35.596191h-48.37181zM234.593524 859.428571h48.347428v35.596191H234.593524zM177.39581 859.428571H129.072762v35.596191h48.323048zM340.114286 859.428571h48.371809v35.596191H340.114286zM498.736762 821.028571h48.347428v35.596191h-48.347428zM445.635048 859.428571h48.371809v35.596191h-48.371809zM551.18019 859.428571v35.596191h48.37181v-35.596191h-6.534095z'
            }
          )
        )
      }

      getLabelShape() {
        return h(
          'text',
          {
            fill: '#000000',
            fontSize: 12,
            x: NodeSize / 2,
            y: NodeSize + 20,
            textAnchor: 'middle',
            dominantBaseline: 'middle'
          },
          '唯一行（哈希值）'
        )
      }

      getShape() {
        const { x, y, width, height } = this.getAttributes()
        const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
        return h(
          'g',
          {
            transform
          },
          [
            h(
              'rect',
              {
                rx: 5,
                ry: 5,
                width: NodeSize,
                height: NodeSize,
                fill: '#fff',
                stroke: '#3D6380',
                strokeWidth: 1
              }
            ),
            this.getIconShape(),
            this.getLabelShape()
          ]
        )
      }
    }
    class Model extends PolygonNodeModel {
      constructor(data, graphModel) {
        super(data, graphModel)
        this.points = [
          [NodeSize / 2, 0],
          [NodeSize, NodeSize / 2],
          [NodeSize / 2, NodeSize],
          [0, NodeSize / 2]
        ]
      }
    }

    return {
      view: Node,
      model: Model
    }
  })
}
